package interfaceGrafica;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle;
import logica.main.MainGrafico;
import logica.util.Data;
import logica.util.TipoDeCadastro;
import logica.util.TipoDeEntradaInvalida;
import logica.veiculo.Acessorio;
import logica.veiculo.Combustivel;
import logica.veiculo.Cor;
import logica.veiculo.Estado;
import logica.veiculo.Freio;
import logica.veiculo.Motocicleta;
import logica.veiculo.Potencia;
import logica.veiculo.Veiculo;
import persistencia.GeradorDeLogs;
import persistencia.MecanismoDePersistenciaSeguro;
import util.Constantes;


/**
 * @author Equipe Localisa (Usa quem precisa!)
 */
@SuppressWarnings("serial")
public class InterfaceMotocicleta extends javax.swing.JPanel {

    /**
	 * 
	 */
	
	private Motocicleta motocicletaAtual;
    private static MecanismoDePersistenciaSeguro mecanismoDePersistenciaClientesFisico;
    private static GeradorDeLogs geradorDeLog;
    List<Veiculo> motocicletasLista;
    List<JCheckBox> listaDeAcessoriosDisponiveis;

    /** Creates new form CadastroMotocicleta */
    public InterfaceMotocicleta() {
        lerDados();
        initComponents();

        try {
            geradorDeLog = new GeradorDeLogs();
        } catch (Exception e) {
        }
        
        try {
			geradorDeLog.escreveLog("Usuario "+MainGrafico.getUsuarioLogado().getLogin()+"entrou na area de gereciamento de motocicletas.");
		} catch (Exception e) {
			
		}
        
        for (Potencia potencia : Potencia.values()) {
            jComboBox2.addItem(potencia);
        }

        for (Cor cor : Cor.values()) {
            jComboBox1.addItem(cor);
        }

        for (Combustivel combustivel : Combustivel.values()) {
            jComboBox3.addItem(combustivel);
        }

        for (Freio tipoDeFreio : Freio.values()) {
            jComboBox4.addItem(tipoDeFreio);
        }

        listaDeAcessoriosDisponiveis = new ArrayList<JCheckBox>();

        for (Veiculo veiculo : motocicletasLista) {
            if (veiculo instanceof Motocicleta) {
                list1.add(veiculo.getMarca() + " # " + veiculo.getModelo() + " # " + veiculo.getPlaca());
            }
            else{
            	motocicletasLista.remove(veiculo);
            }
        }
        jButton5.setEnabled(false);
        jButton3.setEnabled(false);
    }

    @SuppressWarnings("unchecked")
	private void lerDados(){
        try{
            mecanismoDePersistenciaClientesFisico = new MecanismoDePersistenciaSeguro("arquivos/motocicletas.ser");
            motocicletasLista = (ArrayList<Veiculo>) mecanismoDePersistenciaClientesFisico.recuperaDoArquivo();
            if(motocicletasLista == null){
            	motocicletasLista = new ArrayList<Veiculo>();
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Houve um problema no carregamento do banco de dados do Sistema.", null, JOptionPane.ERROR_MESSAGE);
        }

    }

    @SuppressWarnings("unchecked")
	private void persistirDados(){

        try{
           geradorDeLog.escreveLog("Gravado os dados das motocicletas");
           mecanismoDePersistenciaClientesFisico.persisteNoArquivo((ArrayList) this.motocicletasLista);
        }catch(Exception e){
        }

    }

    public void limparCampos(){

        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");
        jTextField5.setText("");
        jTextField6.setText("");
        jTextField7.setText("");
        jTextField8.setText("");
        jTextField9.setText("");
        jTextField10.setText("");


        jLabel2.setForeground(Color.BLACK);
        jLabel3.setForeground(Color.BLACK);
        jLabel4.setForeground(Color.BLACK);
        jLabel5.setForeground(Color.BLACK);
        jLabel7.setForeground(Color.BLACK);
        jLabel10.setForeground(Color.BLACK);
        jLabel12.setForeground(Color.BLACK);
        jLabel13.setForeground(Color.BLACK);
        jLabel17.setForeground(Color.BLACK);

        Iterator<JCheckBox> itListaDeAcessorios = listaDeAcessoriosDisponiveis.iterator();
        while (itListaDeAcessorios.hasNext()) {

            JCheckBox item = (JCheckBox) itListaDeAcessorios.next();
            item.setSelected(false);
        }
    }

    private Acessorio getAcessorioPelaDescricao(String descricao) {
        for (Acessorio acessorio : Acessorio.values()) {
            if (acessorio.getDescricao().equals(descricao)) {
                return acessorio;
            }
        }
        return null;
    }

     private void cadastraMotocicleta(Motocicleta novaMotocicleta, TipoDeCadastro tipoDeCadastro, String mensagemSucesso, String tituloSucesso, String mensagemFalha, String tituloFalha){
        jLabel2.setForeground(Color.BLACK);
        jLabel3.setForeground(Color.BLACK);
        jLabel4.setForeground(Color.BLACK);
        jLabel5.setForeground(Color.BLACK);
        jLabel7.setForeground(Color.BLACK);
        jLabel10.setForeground(Color.BLACK);
        jLabel12.setForeground(Color.BLACK);
        jLabel13.setForeground(Color.BLACK);
        jLabel17.setForeground(Color.BLACK);

        List<TipoDeEntradaInvalida> entradasInvalidas = new ArrayList<TipoDeEntradaInvalida>();

        try {
            novaMotocicleta.setRenavam(jTextField1.getText());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.RENAVAM);
        }

        try {
            novaMotocicleta.setMarca(jTextField2.getText());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.MARCA);
        }

        try {
            novaMotocicleta.setModelo(jTextField5.getText());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.MODELO);
        }

        try {
            novaMotocicleta.setPotencia(Integer.parseInt(jTextField6.getText()));
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.POTENCIA);
        }

        try {
            novaMotocicleta.setPlaca(jTextField8.getText());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.PLACA);
        }

        try {
            int dia = Integer.parseInt(jTextField3.getText().split("/")[0]);
            int mes = Integer.parseInt(jTextField3.getText().split("/")[1]);
            int ano = Integer.parseInt(jTextField3.getText().split("/")[2]);
            novaMotocicleta.setDataDeAquisicao(new Data(dia, mes, ano));
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.DATA);
        }

        try {
            novaMotocicleta.setAno(Integer.parseInt(jTextField4.getText()));
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.ANO);
        }

        try {
            novaMotocicleta.setNivelDoTanque(Integer.parseInt(jTextField7.getText()));
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.NIVEL_DE_TANQUE);
        }

        try {
            novaMotocicleta.setTipoDePotencia((Potencia)jComboBox2.getSelectedItem());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.TIPO_DE_POTENCIA);
        }

        try {
            novaMotocicleta.setCor((Cor)jComboBox1.getSelectedItem());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.COR);
        }

        try {
            novaMotocicleta.setTipoDeCombustivel((Combustivel)jComboBox3.getSelectedItem());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.TIPO_DE_COMBUSTIVEL);
        }

        try {
            novaMotocicleta.setTipoDeFreio((Freio)jComboBox4.getSelectedItem());
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.TIPO_DE_FREIO);
        }

        try {
            List<Acessorio> acessorios = new ArrayList<Acessorio>();
            for (JCheckBox jcheckBox : listaDeAcessoriosDisponiveis) {
                if (jcheckBox.isSelected()) {
                    acessorios.add(getAcessorioPelaDescricao(jcheckBox.getText()));
                }
            }
            novaMotocicleta.setAcessorios(acessorios);
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.ACESSORIOS);
        }

        
        try {
            novaMotocicleta.setEstado(Estado.DISPONIVEL);
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.ESTADO_VEICULO);
        }

         try {
            novaMotocicleta.setCilindradas(Integer.parseInt(jTextField9.getText()));
        } catch (Exception e) {
            entradasInvalidas.add(TipoDeEntradaInvalida.CILINDRADAS);
        }

        if ( entradasInvalidas.size() == 0 ){
            if (! jaExisteMotocicletaIgualNaLista(novaMotocicleta)) {
                motocicletasLista.add(novaMotocicleta);
                try {
        			geradorDeLog.escreveLog("Motocicleta "+novaMotocicleta.getModelo()+" de RENAVAM "+novaMotocicleta.getRenavam()+" foi cadastrada.");
        		} catch (Exception e) {
        			
        		}
                list1.add(novaMotocicleta.getMarca() +" # "+ novaMotocicleta.getModelo() + " # " + novaMotocicleta.getPlaca());
                list1.select(list1.getItemCount()-1);
                JOptionPane.showMessageDialog(null, mensagemSucesso, tituloSucesso,JOptionPane.PLAIN_MESSAGE);
                limparCampos();
                jButton5.setEnabled(false);
                jButton3.setEnabled(false);
                list1.select(-1);
                jButton4.setEnabled(true);
            } else {
                JOptionPane.showMessageDialog(null, "Nao pode haver RENAVAM ou placas duplicadas.", "Mensagem de Erro", JOptionPane.ERROR_MESSAGE);
            }


        } else{
            if (tipoDeCadastro == TipoDeCadastro.EDICAO) {
                list1.add(novaMotocicleta.getMarca() +" # "+ novaMotocicleta.getModelo() + " # " + novaMotocicleta.getPlaca());
                motocicletasLista.add(novaMotocicleta);
                try {
        			geradorDeLog.escreveLog("Motocicleta "+novaMotocicleta.getModelo()+" de RENAVAM "+novaMotocicleta.getRenavam()+" teve seus dados alterados.");
        		} catch (Exception e) {
        			
        		}
                jButton5.setEnabled(false);
                jButton3.setEnabled(false);
                list1.select(-1);
                jButton4.setEnabled(true);
            }
            JOptionPane.showMessageDialog(null, mensagemFalha, tituloFalha,JOptionPane.ERROR_MESSAGE);
 
            for ( TipoDeEntradaInvalida entradaInvalida : entradasInvalidas ){
                if ( entradaInvalida == TipoDeEntradaInvalida.RENAVAM ){
                    jLabel2.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.MARCA ){
                    jLabel3.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.MODELO ){
                    jLabel7.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.POTENCIA ){
                    jLabel10.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.PLACA ){
                    jLabel12.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.DATA ){
                    jLabel4.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.ANO ){
                    jLabel5.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.NIVEL_DE_TANQUE ){
                    jLabel13.setForeground(Color.RED);
                } else if ( entradaInvalida == TipoDeEntradaInvalida.CILINDRADAS ){
                    jLabel17.setForeground(Color.RED);
                }

            }
        }
     }

     private boolean jaExisteMotocicletaIgualNaLista(Motocicleta umaMotocicleta) {
         for (Veiculo veiculo : motocicletasLista) {
             if (veiculo.getRenavam().equals(umaMotocicleta.getRenavam()) || veiculo.getPlaca().equals(umaMotocicleta.getPlaca())) {
                 return true;
             }
         }
         return false;
     }

     private void selecionarMotocicleta( ){
        limparCampos();
        String selecionado = list1.getItems()[list1.getSelectedIndex()];
        String PlacaDaMotocicleta = selecionado.split(" # ")[2];
        for (Veiculo motocicleta : motocicletasLista) {
            if (motocicleta.getPlaca().equals(PlacaDaMotocicleta)) {
                motocicletaAtual = (Motocicleta)motocicleta;
                jButton5.setEnabled(true);
                jButton1.setEnabled(false);
                jButton3.setEnabled(true);
                jTextField1.setText(motocicletaAtual.getRenavam());
                jTextField2.setText(motocicletaAtual.getMarca());
                jTextField3.setText(motocicletaAtual.getDataDeAquisicao().getData());
                jTextField5.setText(motocicletaAtual.getModelo());
                jTextField6.setText(new Integer(motocicletaAtual.getPotencia()).toString());
                jTextField4.setText(new Integer(motocicletaAtual.getAno()).toString());
                jTextField8.setText(motocicletaAtual.getPlaca());
                jTextField7.setText(new Integer(motocicletaAtual.getNivelDoTanque()).toString());
                jTextField9.setText(new Integer(motocicletaAtual.getCilindradas()).toString());
                jComboBox1.setSelectedItem(motocicletaAtual.getCor());
                jComboBox2.setSelectedItem(motocicletaAtual.getTipoDePotencia());
                jComboBox3.setSelectedItem(motocicletaAtual.getTipoDeCombustivel());
                jComboBox4.setSelectedItem(motocicletaAtual.getTipoDeFreio());

                for (JCheckBox jcheckBox : listaDeAcessoriosDisponiveis){
                	jcheckBox.setSelected(false);
                }                
                for (JCheckBox jcheckBox : listaDeAcessoriosDisponiveis) {
                	for ( Acessorio acessorio : motocicletaAtual.getAcessorios() ){
                		if ( jcheckBox.getText().equals(acessorio.getDescricao()) ){
                			jcheckBox.setSelected(true);
                		}
                	}
                }
            }
        }
    }


   
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel15 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel14 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField8 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        {
        	jCheckBox1 = new javax.swing.JCheckBox();
        	jCheckBox1.setText("Cambio Automatico");
        }
        {
        	jCheckBox11 = new javax.swing.JCheckBox();
        	jCheckBox11.setText("GPS");
        }
        {
        	jCheckBox10 = new javax.swing.JCheckBox();
        	jCheckBox10.setText("Freios ABS");
        }
        {
        	jCheckBox2 = new javax.swing.JCheckBox();
        	jCheckBox2.setText("Partida Eletrica");
        }
        {
        	jCheckBox19 = new javax.swing.JCheckBox();
        	jCheckBox19.setText("Alarme");
        }
        {
        	jCheckBox17 = new javax.swing.JCheckBox();
        	jCheckBox17.setText("Escapamento Longo");
        }
        {
        	jCheckBox16 = new javax.swing.JCheckBox();
        	jCheckBox16.setText("Escapamento Duplo");
        }
        {
        	jCheckBox15 = new javax.swing.JCheckBox();
        	jCheckBox15.setText("Air-Bag");
        }
        {
        	jCheckBox14 = new javax.swing.JCheckBox();
        	jCheckBox14.setText("Banco de Couro");
        }
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jTextField7 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JSeparator();
        scrollPane1 = new java.awt.ScrollPane();
        list1 = new java.awt.List();

        this.setPreferredSize(new java.awt.Dimension(687, 392));

        jLabel15.setText("Tipo de Freio:");

        jLabel12.setText("Placa:");

        jLabel14.setText("Acessorios");

        jLabel2.setText("RENAVAM:");

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel1.setText("Cadastro de Motocicleta");

        jLabel4.setText("Data de Aquisicao:");

        jLabel3.setText("Marca:");

        jLabel5.setText("Ano:");

        jLabel10.setText("Potencia:");

        jLabel9.setText("Combustivel:");

        jLabel8.setText("Tipo de Potencia:");

        jLabel7.setText("Modelo:");

        jLabel6.setText("Cor:");

        jButton2.setText("Limpar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel13.setText("Nivel do Tanque:");

        jTextField10.setText("Digite um nome...");

        jLabel16.setText("Consultar:");

        jButton4.setText("Cadastrar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Salvar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton3.setText("Excluir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel17.setText("Cilindradas:");

        jButton6.setText("Voltar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        scrollPane1.add(list1);
        list1.setPreferredSize(new java.awt.Dimension(202, 288));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setVerticalGroup(layout.createSequentialGroup()
        	.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	    .addComponent(jButton1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabel12, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jTextField10, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabel16, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jTextField8, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jTextField1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addGroup(layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	        .addComponent(jTextField2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(jTextField5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(jLabel3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(jLabel7, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(scrollPane1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 333, GroupLayout.PREFERRED_SIZE))
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	        .addGap(27)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jLabel8, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jTextField6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel10, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jComboBox2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jComboBox3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel9, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jComboBox1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jComboBox4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel15, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jTextField9, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel17, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jTextField7, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel13, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jTextField3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jTextField4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jLabel5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup()
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	                .addComponent(jSeparator2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
        	                .addComponent(jSeparator1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	            .addComponent(jLabel14, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jCheckBox1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox16, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox14, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jCheckBox10, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox17, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox15, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jCheckBox19, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jCheckBox11, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
        	        .addComponent(jSeparator4, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jButton3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jButton4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	        .addGap(15)
        	        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	            .addComponent(jButton2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jButton5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jButton6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))))
        	.addContainerGap());
        layout.setHorizontalGroup(layout.createSequentialGroup()
        	.addGroup(layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createParallelGroup()
        	        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jCheckBox11, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                .addComponent(jLabel3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	            .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jButton5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE)
        	                .addComponent(jButton4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE))
        	            .addGap(177))
        	        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	            .addComponent(jCheckBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addGap(11)
        	            .addGroup(layout.createParallelGroup()
        	                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                    .addComponent(jCheckBox14, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE)
        	                    .addGap(189))
        	                .addGroup(layout.createSequentialGroup()
        	                    .addGroup(layout.createParallelGroup()
        	                        .addComponent(jLabel14, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                            .addComponent(jCheckBox19, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
        	                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))
        	                        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                            .addComponent(jCheckBox15, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
        	                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))
        	                        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                            .addPreferredGap(jCheckBox19, jComboBox2, LayoutStyle.ComponentPlacement.INDENT)
        	                            .addComponent(jComboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                            .addGap(31)))
        	                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	                    .addGroup(layout.createParallelGroup()
        	                        .addGroup(layout.createSequentialGroup()
        	                            .addGroup(layout.createParallelGroup()
        	                                .addComponent(jLabel13, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jLabel10, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(45)))
        	                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	                            .addGroup(layout.createParallelGroup()
        	                                .addComponent(jTextField7, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
        	                                .addComponent(jTextField6, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
        	                                .addComponent(jTextField5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
        	                                .addComponent(jTextField8, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addGap(19)
        	                                    .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(53)))
        	                            .addGap(21))
        	                        .addGroup(layout.createSequentialGroup()
        	                            .addGroup(layout.createParallelGroup()
        	                                .addComponent(jLabel7, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jLabel12, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(11)))
        	                            .addGroup(layout.createParallelGroup()
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jCheckBox2, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(34))
        	                                .addComponent(jCheckBox17, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE)
        	                                .addComponent(jCheckBox16, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jTextField4, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(53))
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(7)
        	                                    .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(15)))
        	                            .addGap(40))
        	                        .addGroup(layout.createSequentialGroup()
        	                            .addPreferredGap(jLabel13, jSeparator2, LayoutStyle.ComponentPlacement.INDENT)
        	                            .addGroup(layout.createParallelGroup()
        	                                .addComponent(jSeparator2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 222, GroupLayout.PREFERRED_SIZE)
        	                                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                                    .addComponent(jLabel5, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                                    .addGap(194))))))))
        	        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jSeparator1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)
        	                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                    .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                    .addGap(10))
        	                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                    .addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                    .addGap(19)))
        	            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	            .addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
        	            .addGap(252))
        	        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jLabel17, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                    .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                    .addGap(10)))
        	            .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
        	            .addGap(290))
        	        .addGroup(layout.createSequentialGroup()
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jLabel15, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                .addComponent(jCheckBox10, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                    .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                    .addGap(6)))
        	            .addGroup(layout.createParallelGroup()
        	                .addComponent(jTextField9, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
        	                .addGroup(layout.createSequentialGroup()
        	                    .addPreferredGap(jTextField9, jComboBox4, LayoutStyle.ComponentPlacement.INDENT)
        	                    .addGroup(layout.createParallelGroup()
        	                        .addComponent(jComboBox4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	                        .addComponent(jComboBox3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	                    .addGap(84)))
        	            .addGap(252))
        	        .addComponent(jSeparator4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 458, GroupLayout.PREFERRED_SIZE)
        	        .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	            .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	            .addGap(267)))
        	    .addGroup(layout.createSequentialGroup()
        	        .addGap(30)
        	        .addGroup(layout.createParallelGroup()
        	            .addComponent(jButton2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
        	            .addComponent(jButton3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE))
        	        .addGap(330)))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addGroup(layout.createParallelGroup()
        	    .addGroup(layout.createSequentialGroup()
        	        .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 207, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 0, Short.MAX_VALUE))
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	        .addComponent(jLabel16, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addComponent(jTextField10, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
        	        .addGap(16)
        	        .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 10, Short.MAX_VALUE)))
        	.addContainerGap(16, 16));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        limparCampos();
        jButton5.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        Motocicleta novaMotocicleta = new Motocicleta();
        cadastraMotocicleta(novaMotocicleta, TipoDeCadastro.NOVA_ENTRADA, "Cadastro efetuado com sucesso.", "Cadastro realizado", "O cadastro falhou. Os campos errados estao em destaque.", "Cadastro falhou");
        persistirDados();
        list1.select(-1);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        limparCampos();
        if ( motocicletaAtual != null ){
            list1.remove(motocicletaAtual.getMarca()+" # "+motocicletaAtual.getModelo()+" # "+motocicletaAtual.getPlaca());
            motocicletasLista.remove(motocicletaAtual);
            try {
    			geradorDeLog.escreveLog("Motocicleta "+motocicletaAtual.getModelo()+" de RENAVAM "+motocicletaAtual.getRenavam()+" foi removida do sistema.");
    		} catch (Exception e) {
    			
    		}
            motocicletaAtual = null;
            jButton3.setEnabled(false);
            jButton4.setEnabled(true);
            jButton5.setEnabled(false);
            list1.select(-1);
            JOptionPane.showMessageDialog(null, "Automovel excluido com sucesso!", "Automovel removido", JOptionPane.PLAIN_MESSAGE);
            persistirDados();
        }
        else{
            JOptionPane.showMessageDialog(null, "Voce deve selecionar um automovel para ser excluido!", "Automovel nao especificado", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        list1.remove(motocicletaAtual.getMarca()+" # "+motocicletaAtual.getModelo()+" # "+motocicletaAtual.getPlaca());
        motocicletasLista.remove(motocicletaAtual);
        cadastraMotocicleta(motocicletaAtual, TipoDeCadastro.EDICAO, "Edicao realizada com sucesso.", "Edicao realizada", "A edicao falhou. Verifique campos em destaque.", "Edicao nao realizada");
        persistirDados();
        jButton3.setEnabled(false);
        jButton4.setEnabled(true);
        jButton5.setEnabled(false);
        list1.select(-1);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String parametroDeConsulta = jTextField10.getText();

        String[] consultados = list1.getItems();

        for ( int i=0; i<consultados.length; i++ ){
            if ( (consultados[i].toLowerCase()).
                    contains(parametroDeConsulta.toLowerCase()) ){
                list1.select(i);
                jTextField10.setText("");
                selecionarMotocicleta();
                break;
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        MainGrafico.entrarNaArea(MainGrafico.getMenuCorrente(), Constantes.INTERFACE_TAMANHO_MENU[0], Constantes.INTERFACE_TAMANHO_MENU[1]);
        MainGrafico.sairDaArea(this);
    }//GEN-LAST:event_jButton6ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox10;
    private javax.swing.JCheckBox jCheckBox11;
    private javax.swing.JCheckBox jCheckBox14;
    private javax.swing.JCheckBox jCheckBox15;
    private javax.swing.JCheckBox jCheckBox16;
    private javax.swing.JCheckBox jCheckBox17;
    private javax.swing.JCheckBox jCheckBox19;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private java.awt.List list1;
    private java.awt.ScrollPane scrollPane1;
    // End of variables declaration//GEN-END:variables

}
